#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>

int main(int argc, char **argv)
{

    int shmid;
    shmid = shmget((size_t)0x4004, 1024, 0640 | IPC_CREAT);
    if (shmid == -1)
    {
        perror("shmget is error");
        exit(1);
    }
    char *ptext = (char *)shmat(shmid, 0, 0);
    sprintf(ptext,"this is pid = %d\n",getpid());
    printf(" 获得的值是: %s \n",ptext);
    
    
    shmdt(ptext);
    shmctl(shmid,IPC_RMID,0);
    

    return 0;
}